package com.suke.czx.modules.wx.controller;

import java.net.URLEncoder;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author Edward
 */
@Controller
@RequestMapping("/wx/redirect/{appid}")
public class WxRedirectController {


	@RequestMapping()
	public String redirecturl(@PathVariable String appid,@RequestParam(required=true) String url){
		String randomstr = RandomStringUtils.random(9, "123456789");
		String url_a =  "redirect:https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+"&redirect_uri=";
		String url_b = "&response_type=code&scope=snsapi_userinfo&state="+randomstr+"#wechat_redirect";
		return url_a+URLEncoder.encode(url)+url_b;
		
	}
	
}
